package com.nothingboard.module.board.model;


public class PagingDto {
	
	/** 현재페이지번호 또는 요청페이지번호 */
	private long currentPageNo;
	/** 게시물합계 */
	private long totalPostCount;
	/** 보여줄 게시물 갯수 */
	private int postCount;
	/** 보여줄 페이지 번호 갯수 */
	private int pageCount;
	/** 최대페이지번호 */
	private long maxPageNo;
	/** 최소페이지번호 */
	private long minPageNo = 1;
	/** 마지막 페이지번호 */
	private long lastPageLinkNo;
	/** 처음페이지번호 */
	private int firstPageLinkNo = 1;
	/** 다음페이지번호 */
	private long nextPageLinkNo;
	/** 이전페이지번호 */
	private long prevPageLinkNo;
	/** 화면 출력 시작 페이지 번호 */
	private long startPageNo;
	/** 환면 출력 마지막 페이지 번호 */
	private long endPageNo;
	
	public PagingDto(long total, long curr, int post, int page){
		totalPostCount = total;
		currentPageNo = curr;
		postCount = post;
		pageCount = page;
	}
	public void  setCalculation(){
		if(totalPostCount > 0 && postCount > 0){
			maxPageNo = totalPostCount / postCount;
			if(totalPostCount % postCount > 0){
				maxPageNo ++;
			}
			
			if(currentPageNo > maxPageNo) currentPageNo = maxPageNo;
			
			startPageNo = ((currentPageNo - 1) / pageCount) * pageCount + 1;
			endPageNo = startPageNo + pageCount - 1;
			
			if(endPageNo > maxPageNo) endPageNo = maxPageNo;
			
			if(maxPageNo > endPageNo){
				nextPageLinkNo = startPageNo + pageCount;
				lastPageLinkNo = maxPageNo;
			}else{
				nextPageLinkNo = -1;
				lastPageLinkNo = -1;
			}
			
			if(startPageNo > minPageNo){
				prevPageLinkNo = startPageNo - pageCount;
				if(prevPageLinkNo < minPageNo) prevPageLinkNo = minPageNo;
			}
		}
	}
	
	public long getCurrentPageNo() {
		return currentPageNo;
	}
	public void setCurrentPageNo(long currentPageNo) {
		this.currentPageNo = currentPageNo;
	}
	public long getTotalPostCount() {
		return totalPostCount;
	}
	public void setTotalPostCount(long totalPostCount) {
		this.totalPostCount = totalPostCount;
	}
	public int getPostCount() {
		return postCount;
	}
	public void setPostCount(int postCount) {
		this.postCount = postCount;
	}
	public int getPageCount() {
		return pageCount;
	}
	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}
	public long getMaxPageNo() {
		return maxPageNo;
	}
	public void setMaxPageNo(long maxPageNo) {
		this.maxPageNo = maxPageNo;
	}
	public long getMinPageNo() {
		return minPageNo;
	}
	public void setMinPageNo(long minPageNo) {
		this.minPageNo = minPageNo;
	}
	public long getLastPageLinkNo() {
		return lastPageLinkNo;
	}
	public void setLastPageLinkNo(long lastPageLinkNo) {
		this.lastPageLinkNo = lastPageLinkNo;
	}
	public int getFirstPageLinkNo() {
		return firstPageLinkNo;
	}
	public void setFirstPageLinkNo(int firstPageLinkNo) {
		this.firstPageLinkNo = firstPageLinkNo;
	}
	public long getNextPageLinkNo() {
		return nextPageLinkNo;
	}
	public void setNextPageLinkNo(long nextPageLinkNo) {
		this.nextPageLinkNo = nextPageLinkNo;
	}
	public long getPrevPageLinkNo() {
		return prevPageLinkNo;
	}
	public void setPrevPageLinkNo(long prevPageLinkNo) {
		this.prevPageLinkNo = prevPageLinkNo;
	}
	public long getStartPageNo() {
		return startPageNo;
	}
	public void setStartPageNo(long startPageNo) {
		this.startPageNo = startPageNo;
	}
	public long getEndPageNo() {
		return endPageNo;
	}
	public void setEndPageNo(long endPageNo) {
		this.endPageNo = endPageNo;
	}

}
